package tests;

import static org.junit.Assert.*;

import java.util.Vector;

import java.util.GregorianCalendar;

import model.AppointmentDataModel;
import model.CategoryDataModel;


import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import controller.*;
import model.*;
import sql.*;

/**
 * 
 * @author Erwin Cavas.
 *
 */

public class TestAppointmentController {
	private static AppointmentController appCtrler;
	private static SqlConnector sqlConn;
	private static AppointmentModel appModel;
	private static AppointmentDataModel appointment;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		sqlConn = new SqlConnector("test.db");
		sqlConn.createTable();
		appModel = new AppointmentModel(sqlConn);
		appCtrler = new AppointmentController(appModel);
		appointment = new model.AppointmentDataModel(1, "TestTitel", new GregorianCalendar(2010, 01, 19, 11, 58, 00), 
				new GregorianCalendar(2010, 01, 22, 11, 58, 00), "School", "TestMoFo", new CategoryDataModel(1, "cat_title"), "erwin");
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testAppointmentController() {
		
	}
	
	@Test
	public void newAppointment() {
		appModel.addAppointment(appointment);
	}
	@Test
	public void testNewAppointment(){
		assertEquals("erwin", appModel.getAppointment(1).getDescription());
	}
	
	@Test
	public void editAppointment() {
		//appCtrler.editAppointment(appointment);
	}
	
	
	@Test
	public void convertDataToDateTime(){
		assertEquals("1999-02-01 13:11", appCtrler.convertDataToDateTime("1999", "02", "01", "13", "11"));
	}
	
	@Test
	public void getCategoryList() {
			
	}
	
	@Test
	public void isValidDate() {
		assertTrue(appCtrler.isValidDate("1999-02-27 15:11"));
	}
	
	@Test
	public void startIsBeforeEnd() {
		assertTrue(appCtrler.startIsBeforeEnd("1994-02-12 15:11", "1994-03-12 15:11"));
	}
	
	@Test
	public void getAllCategories() {
	}
	
	@Test
	public void searchAppointments() {
		Vector<AppointmentDataModel> appointments = appCtrler.searchAppointments("erwin");
		assertEquals(appointments.size(), 1);
		
		AppointmentDataModel appointment = appointments.get(0);
		assertEquals(appointment.getDescription(), "erwin");
	}
	
	@Test
	public void deleteAppointment() {
		appCtrler.deleteAppointment(1);		
	}
}
